import * as task from "../../api/task";

Page({
    data: {
        currentPage:1,
        list:[],
        currentPage:1,
        hasNextPage:true,
        total:"",
        taskRange:[],
        taskStatusRange:[{
            label:"进行中",
            value:1
        },{
            label:"已结束",
            value:2
        }],

        taskName:"",
        taskStatus:""
    },
    onLoad(){

        task.getIncreaseTaskList({
            currentPage:this.data.currentPage,
            pageSize:10000,
        })
        .then((res)=>{
            let list = [];
            if(res.list && res.list.length > 0){
                res.list.map((el)=>{
                    list.push({
                        label:el.taskName,
                        value:el.taskName
                    })
                })
            }
            this.setData({
                taskRange:list,
                taskName: list.length > 0 ? list[0].label : '',
                taskStatus:1
            });

            this.get_order_list();

        })

    },
    confirm_task_name(item){
        this.setData({
            currentPage:1,
            taskName:item.detail.value,
            hasNextPage:true,
            list:[]
        })
        this.get_order_list();
    },
    confirm_task_state(item){
        this.setData({
            currentPage:1,
            taskStatus:item.detail.value,
            hasNextPage:true,
            list:[]
        })
        this.get_order_list();
    },
    get_order_list(){
        task.getIncreaseTaskList({
            currentPage:this.data.currentPage,
            pageSize:10,
            taskStatus:this.data.taskStatus,
            taskName:this.data.taskName
        })
        .then((res)=>{

            this.setData({
                list:this.data.currentPage == 1 ? res.list :[...this.data.list, ...res.list],
                hasNextPage:res.hasNextPage,
                total:res.total
            })
        })
    },
    handle_to_detail(e){
        let { item } = e.currentTarget.dataset;
        wx.navigateTo({
            url: '/pages/my-task-detail/my-task-detail?taskNo='+item.taskNo+"&taskName="+item.taskName
        });
    },
    onReachBottom(){
        if(this.data.hasNextPage){
            this.setData({
                currentPage: ++this.data.currentPage
            })
            this.get_order_list();
        }
    }
})
